home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / 80X86 / DOS32V33.ZIP / EXAMPLES / MEMSPEED.ASM < prev    next >
Encoding:
Assembly Source File  |  1995-10-18  |  10.7 KB  |  401 lines

  1. ;***************************************************************************
  2. ; MEMSPEED.ASM      A program will show the video card memory trasnfer speed.
  3. ;
  4. ;
  5. ; This code is not written very effiecently at all. I only wrote it
  6. ; because I am soon going to upgrade my computer and I needed somthing
  7. ; to test the video and cpu memory transfer rates of variuos computers
  8. ; and video cards. This way I can be sure if I am buying a fast video card.
  9. ;
  10. ;***************************************************************************
  11.  
  12. .386
  13.  
  14. .MODEL FLAT
  15. .STACK 4000h
  16.  
  17. PIC_FREQ    EQU    1193180 ;Hz
  18. DURATION        EQU     18
  19.  
  20. CRLF        EQU     13,10
  21.  
  22.  
  23. ;  Macro to print some text on the screem
  24. ;
  25. Print MACRO string
  26. local @text,@skip
  27.     mov edx,offset @text
  28.     mov ah,9
  29.     int 21h
  30.     jmp @skip
  31. @text db string,36
  32. @skip:
  33. ENDM
  34.  
  35. LOC STRUC
  36. _d    dd ?
  37. _w    dd 0
  38. _b    dd 0
  39. _mov32    dd 0
  40. LOC ENDS
  41.  
  42. FILL_TYPE STRUC
  43. Video        LOC <>
  44. CPU        LOC <>
  45. Video_Video    LOC <>
  46. CPU_Video    LOC <>
  47. CPU_CPU        LOC <>
  48. FILL_TYPE ENDS
  49.  
  50.  
  51.     .DATA
  52.  
  53. TempBuffer    DB     1024*20 DUP (?)
  54. TempBuffer2     DB     1024*20 DUP (?)
  55. VideoPtr        DD      ?
  56. Ticks           DD      ?
  57. old_INT8        DF      ?
  58.  
  59. extrn Debug :Near
  60.  
  61.     .CODE
  62.  
  63. NumberWrites    FILL_TYPE   <>
  64.  
  65. Print_Kbs PROC
  66.         mov    ebx,PIC_FREQ
  67.         mul    ebx
  68.         mov     ebx,DURATION*65536
  69.         div    ebx
  70.         push    eax
  71.         shr     eax,10
  72.         call    Print_DecDword
  73.         Print   ' Kb/s'
  74.         pop    eax
  75.     Ret
  76. Print_Kbs ENDP
  77.  
  78.  
  79. Video_Speed PROC                            ; Start of program
  80.  
  81.     ;****** make sure timer 0 is set to full scale **********
  82.  
  83.         mov     al,00110100b     ; SET TIMER VALUE TO ZERO ( 18.2 Hz )
  84.         out     43h,al
  85.         mov     al,0
  86.         out     40h,al
  87.         out     40h,al
  88.  
  89.  
  90.         mov     ax,13h                    ; Reset TEXT mode
  91.         int     10h
  92.  
  93.   ;******* get offset address (near pointer) to video text memory ********
  94.         mov     ax,0EE02h
  95.         int     31h
  96.         neg     ebx
  97.         add     ebx,0A0000h
  98.         mov     VideoPtr,ebx
  99.  
  100.     ;****** hook timer interrupt **********
  101.         mov     ax,204h
  102.         mov     bl,8
  103.         int     31h
  104.         mov     dword ptr old_INT8,edx          ; save old vector
  105.         mov     word ptr old_INT8[4],cx
  106.  
  107.         mov     ax,205h
  108.         mov     edx,Offset Timer_ISR            ; put in new vector
  109.         mov     cx,cs
  110.         int     31h
  111.  
  112.  ;------------ fill video memory with REP STOSD for a set amount of time --------
  113.         mov     Ticks,0
  114.         mov    eax,0
  115. Loop00:
  116.         mov     edi,VideoPtr
  117.         mov     ecx,320*20
  118.         add     NumberWrites.Video._d, 320*20
  119.         shr    ecx,2
  120.         rep     stosd
  121.         inc     al
  122.         inc     ah
  123.         push    ax
  124.         push    ax
  125.         pop    eax
  126.         cmp     Ticks,DURATION
  127.         jb Loop00
  128.  
  129.  ;------------ fill video memory with REP STOSW for a set amount of time --------
  130.         mov     Ticks,0
  131.         mov    eax,0
  132. Loop01:
  133.         mov     edi,VideoPtr
  134.         mov     ecx,320*20
  135.         add     NumberWrites.Video._w, ecx
  136.         shr    ecx,1
  137.         rep     stosw
  138.         inc     al
  139.         inc     ah
  140.         cmp     Ticks,DURATION
  141.         jb Loop01
  142.  
  143.  ;------------ fill video memory with REP STOSB for a set amount of time --------
  144.         mov     Ticks,0
  145.         mov    eax,0
  146. Loop02:
  147.         mov     edi,VideoPtr
  148.         mov     ecx,320*20
  149.         add     NumberWrites.Video._b, ecx
  150.         rep     stosb
  151.         inc     al
  152.         cmp     Ticks,DURATION
  153.         jb Loop02
  154.  
  155.  ;------------ fill CPU memory with REP STOSD for a set amount of time --------
  156.         mov     Ticks,0
  157. Loop03:
  158.         mov     edi,OFFSET TempBuffer
  159.         mov     ecx,SIZE TempBuffer
  160.         add     NumberWrites.CPU._d,ecx
  161.         shr    ecx,2
  162.         rep     stosd
  163.         cmp     Ticks,DURATION
  164.         jb Loop03
  165.  
  166.  ;------------ fill CPU memory with MOV for a set amount of time --------
  167.         mov     Ticks,0
  168.         xor     eax,eax
  169.  
  170. Loop03a:
  171.         mov     edi,OFFSET TempBuffer
  172.      align 4
  173. Loop03a_:
  174. REPT 8
  175.         mov     [edi],eax
  176.         mov     [edi+4],eax
  177.         mov     [edi+8],eax
  178.         mov     [edi+12],eax
  179.         mov     [edi+16],eax
  180.         mov     [edi+20],eax
  181.         mov     [edi+24],eax
  182.         mov     [edi+28],eax
  183.         add     edi,32
  184. ENDM
  185.         add     NumberWrites.CPU._mov32,32*8
  186.         cmp     edi,SIZE TempBuffer + OFFSET TempBuffer
  187.         jae     Loop03a
  188.         cmp     Ticks,DURATION
  189.         jb Loop03a_
  190.  
  191.  ;------- trasnfer CPU 2 Video memory with REP MOVSD for a set amount of time --------
  192.         mov     Ticks,0
  193. Loop04:
  194.         mov     edi,VideoPtr
  195.         mov     esi,OFFSET TempBuffer
  196.         mov     ecx,SIZE TempBuffer
  197.         add     NumberWrites.CPU_Video._d,ecx
  198.         shr    ecx,2
  199.         rep     movsd
  200.         cmp     Ticks,DURATION
  201.         jb Loop04
  202.  
  203.  ;---- trasnfer CPU 2 Video memory with MOV 32 bit for a set amount of time --------
  204.         mov     Ticks,0
  205. Loop05:
  206.         mov     edi,VideoPtr
  207.         mov     esi,OFFSET TempBuffer
  208.         mov     ecx,SIZE TempBuffer
  209.         Align 4
  210. flop05:
  211. REPT    4
  212.     MOV    EAX,[ESI]
  213.     MOV    [EDI],EAX
  214.     MOV    EAX,[ESI+4]
  215.     MOV    [EDI+4],EAX
  216.     MOV    EAX,[ESI+8]
  217.     MOV    [EDI+8],EAX
  218.     MOV    EAX,[ESI+12]
  219.     MOV    [EDI+12],EAX
  220.     MOV    EAX,[ESI+16]
  221.     MOV    [EDI+16],EAX
  222.     MOV    EAX,[ESI+20]
  223.     MOV    [EDI+20],EAX
  224.     MOV    EAX,[ESI+24]
  225.     MOV    [EDI+24],EAX
  226.     MOV    EAX,[ESI+28]
  227.     MOV    [EDI+28],EAX
  228.         ADD     EDI,32
  229.         ADD     ESI,32
  230.     SUB    ECX,32
  231. ENDM
  232.         add     NumberWrites.CPU_Video._mov32,4*32
  233.     and    ecx,ecx
  234.         jz      Loop05
  235.     cmp     Ticks,DURATION
  236.         jb      flop05
  237.  
  238.  ;------------ CPU 2 CPU using MOVSD  for a set amount of time --------
  239.         mov     Ticks,0
  240. Loop06:
  241.         mov     esi,OFFSET TempBuffer
  242.         mov     edi,OFFSET TempBuffer2
  243.         mov     ecx,SIZE TempBuffer
  244.         add     NumberWrites.CPU_CPU._d,ecx
  245.         shr    ecx,2
  246.         rep     movsd
  247.     cmp     Ticks,DURATION
  248.         jb Loop06
  249.  
  250.  ;------------ CPU 2 CPU using 32bit MOV  for a set amount of time --------
  251.         mov     Ticks,0
  252. Loop07:
  253.         mov     esi,OFFSET TempBuffer
  254.         mov     edi,OFFSET TempBuffer
  255.         mov     ecx,SIZE TempBuffer
  256.         Align 4
  257. flop07:
  258. REPT    4
  259.     MOV    EAX,[ESI]
  260.     MOV    [EDI],EAX
  261.     MOV    EAX,[ESI+4]
  262.     MOV    [EDI+4],EAX
  263.     MOV    EAX,[ESI+8]
  264.     MOV    [EDI+8],EAX
  265.     MOV    EAX,[ESI+12]
  266.     MOV    [EDI+12],EAX
  267.     MOV    EAX,[ESI+16]
  268.     MOV    [EDI+16],EAX
  269.     MOV    EAX,[ESI+20]
  270.     MOV    [EDI+20],EAX
  271.     MOV    EAX,[ESI+24]
  272.     MOV    [EDI+24],EAX
  273.     MOV    EAX,[ESI+28]
  274.     MOV    [EDI+28],EAX
  275.         ADD     EDI,32
  276.         ADD     ESI,32
  277.         SUB     ECX,32
  278. ENDM
  279.         add     NumberWrites.CPU_CPU._mov32,4*32
  280.         and     ecx,ecx
  281.         jz      Loop07
  282.     cmp     Ticks,DURATION
  283.         jb      flop07
  284.  
  285.  
  286.  
  287.  
  288.         ;******* reset text mode **********
  289.         mov     ax,3
  290.         int     10h
  291.  
  292.  
  293.         ;******* return origonal interrupt vector **********
  294.         mov     ax,205h
  295.         mov     edx,dword ptr old_INT8
  296.         mov     cx,word ptr old_INT8[4]
  297.         mov     bl,8
  298.         int     31h
  299.  
  300.         ;******* print transfer rates on the screen **********
  301.  
  302.         Print   <'             Memory transfer rates using various methods                ',CRLF>
  303.         Print   <'░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓░▓',CRLF>
  304.         Print   <CRLF,' Video memory fill using REP STOSD ──────────────── '>
  305.         mov     eax,NumberWrites.Video._d
  306.         call    Print_Kbs
  307.         Print   <CRLF,' Video memory fill using REP STOSW ──────────────── '>
  308.         mov     eax,NumberWrites.Video._w
  309.         call    Print_Kbs
  310.         Print   <CRLF,' Video memory fill using REP STOSB ──────────────── '>
  311.         mov     eax,NumberWrites.Video._b
  312.         call    Print_Kbs
  313.         Print   <CRLF,' CPU memory fill  using REP STOSD ───────────────── '>
  314.         mov     eax,NumberWrites.CPU._d
  315.         call    Print_Kbs
  316.         Print   <CRLF,' CPU memory fill 32bit MOV ──────────────────────── '>
  317.         mov     eax,NumberWrites.CPU._mov32
  318.         call    Print_Kbs
  319.         Print   <CRLF,' CPU to CPU transfer using REP MOVSD ────────────── '>
  320.         mov     eax,NumberWrites.CPU_CPU._d
  321.         call    Print_Kbs
  322.         Print   <CRLF,' CPU to CPU transfer using 32bit MOV ────────────── '>
  323.         mov     eax,NumberWrites.CPU_CPU._mov32
  324.         call    Print_Kbs
  325.         Print   <CRLF,' CPU to Video transfer using REP MOVSD ──────────── '>
  326.         mov     eax,NumberWrites.CPU_Video._d
  327.         call    Print_Kbs
  328.         Print   <CRLF,' CPU to Video transfer using 32bit MOV ──────────── '>
  329.         mov     eax,NumberWrites.CPU_Video._mov32
  330.         call    Print_Kbs
  331.  
  332.  
  333.         Print   <CRLF,CRLF>
  334.         Print   <'  The 32bit MOV is using the following instructions repetivily', CRLF>
  335.         Print   <'    mov eax,[esi]                mov [edi],eax    ',CRLF>
  336.         Print   <'    mov [edi],eax                mov [edi+4],eax  ',CRLF>
  337.         Print   <'    mov eax,[esi+4]     or       mov [edi+8],eax  ',CRLF>
  338.         Print   <'    mov [edi+4],eax              mov [edi+12],eax ',CRLF>
  339.         Print   <'    .. ect                       .. ect ',CRLF>
  340.  
  341.         Print   <CRLF>
  342.  
  343.     Print   <'Values may viary upto ±2% when ran at different times.', CRLF, CRLF>
  344.     Print   <'Press any key to exit.', CRLF>
  345.  
  346.         mov     ah,0        ; Wait for a key ( using BIOS service )
  347.         int     16h
  348.  
  349.  
  350.         mov   ax,4C00h                          ; Termiate the program
  351.         int   21h
  352.  
  353. Video_Speed ENDP
  354.  
  355. Timer_ISR PROC
  356.         Push    eax
  357.         Push    ds
  358.         mov     ax,SEG Timer_ISR
  359.         mov     ds,ax
  360.         inc     Ticks
  361.         mov     al,20h
  362.         out     20h,al
  363.         Pop     ds
  364.         Pop     eax
  365.         iretd
  366. Timer_ISR ENDP
  367.  
  368.  
  369. ;╒══════════════════════════════════════════════════════════════════════════╕
  370. ;│                                                                          │
  371. ;│  procedure to print the Decimal value of EAX                             │
  372. ;│                                                                          │
  373. ;└──────────────────────────────────────────────────────────────────────────
  374. ; ***************  prints decimal EAX  ******************
  375. Print_DecDword   PROC
  376.         pushad
  377.         mov     ESI,4*5
  378.         mov     ecx,eax
  379. dec83:
  380.         mov    eax,ECX
  381.         xor    edx,edx
  382.         div     dec_divider[ESI]
  383.         mov    ECX,EDX        ; reuse remainder
  384.                 add al,'0'      ; use quotient as digit number
  385.                 mov     dl,al
  386.                 mov     ah,2
  387.                 int     21h             ; send character to screen
  388.         sub ESI,4
  389.         jge dec83
  390.         popad
  391.         RET
  392. Print_DecDword        ENDP
  393.  
  394.  
  395. align 4
  396. dec_divider dd 1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000
  397. ;-------------------------------------------------------
  398.  
  399.  
  400. END  Video_Speed
  401.